import { getAppCenterApplicationResData } from '@/services/account/getArr';
import { queryWebMenusResData } from '@/services/LoginPower';

const module: { [key: string]: { default: string } } = import.meta.glob('@/assets/icons/applist/*', { eager: true });

export class AppMenuEntity {
  static fromMenu(menu: queryWebMenusResData) {
    return new AppMenuEntity({
      name: menu.name,
      id: menu.menuId,
      code: menu.code,
      icon: menu.level == 2 ? module[`/src/assets/icons/applist/${menu.code}.png`]?.default : '',
      description: '',
      type: menu.menuType,
      level: menu.level || NaN,
      parentId: menu.parentId,
      auditType: menu.auditType || 0,
      intercept: false,
    });
  }

  static fromApp(app: getAppCenterApplicationResData, intercept = false) {
    return new AppMenuEntity({
      name: app.name,
      id: app.applyId,
      code: app.number,
      icon: app.logo,
      description: app.describe,
      type: 3,
      level: 2,
      parentId: 'systemidqitayingyong',
      auditType: app.auditType || 0,
      intercept,
    });
  }

  name: string;
  id: string;
  code: string;
  level: number;
  type: number;
  parentId: string;
  auditType: number;
  icon?: string;
  description?: string;
  intercept?: boolean;

  constructor(entityLike: AppMenuEntity) {
    this.name = entityLike.name;
    this.id = entityLike.id;
    this.code = entityLike.code;
    this.type = entityLike.type;
    this.level = entityLike.level;
    this.parentId = entityLike.parentId;
    this.auditType = entityLike.auditType;
    this.icon = entityLike.icon;
    this.description = entityLike.description;
    this.intercept = entityLike.intercept;
  }
}
